package com.example.powernodemall.model;

import com.example.powernodemall.ProjectEnum.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result<K> {
    private Integer code;
    private String msg;
    private K data;

    public static <T> Result<T> Success(T data) {
        Result<T> result = new Result<>();
        result.code= ResultEnum.SUCCESS.getCode();
        result.msg = ResultEnum.SUCCESS.getMsg();
        result.data = data;
        return result;
    }

    public static Result<Object> Failure(ResultEnum resultEnum) {
        Result<Object> result = new Result<>();
        result.code= resultEnum.getCode();
        result.msg = resultEnum.getMsg();
        result.data = null;
        return result;
    }

    public static Result<Object> Failure(ResultEnum resultEnum, String msg) {
        Result<Object> result = new Result<>();
        result.code= resultEnum.getCode();
        result.msg = msg;
        result.data = null;
        return result;
    }
}
